// 专用小模板
import { reqBannerList, reqCategory, reqFloorList } from '@/api'
// 任何小仓库中:state,mutations,actions,getters

let state = {
    // 商品分类的数据
    category: [],
    // 首页轮播图的数据
    bannerList: [],
    // floor数据
    floorList: [],

};
let mutations = {
    GETCATEGORY(state, category) {
        state.category = category;
    },

    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList

    },

    GETFLOORLIST(state, floorList) {
        state.floorList = floorList

    }

};
let actions = {
    // 商品分类的actions
    async getCategory({ commit, dispatch, state }) {
        let result = await reqCategory();
        if (result.code == 200) {
            commit('GETCATEGORY', result.data)
        }

    },

    //获取banner图的action
    async getBannerList({ commit, dispatch, state }) {
        // 获取首页数据
        let result = await reqBannerList();
        if (result.code == 200) {
            commit('GETBANNERLIST', result.data)
        }
    },

    // 获取Floor组件中的数据
    async getFloorList({ commit, dispatch, state }) {
        let result = await reqFloorList();
        if (result.code == 200) {
            // console.log(result.data)
            commit('GETFLOORLIST', result.data)
        }

    }
};
let getters = {};


// 对外暴露小仓库
export default {
    state,
    mutations,
    actions,
    getters,
}